package com.medicine.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqListener {

    @RabbitListener(queues = "simple.queue")
    public void onMessage(String msg) {
        log.info("收到消息: {}", msg);
    }

    @RabbitListener(queues = "work.queue")
    public void workQueue1(String msg) throws InterruptedException {
        log.info("收到消息1: {}", msg);
        Thread.sleep(20);
    }

    @RabbitListener(queues = "work.queue")
    public void workQueue2(String msg) throws InterruptedException {
        System.err.println("收到消息2: {}" + msg);
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void fanoutQueue1(String msg) {
        log.info("fanout.queue1收到消息: {}", msg);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void fanoutQueue2(String msg) {
        log.info("fanout.queue2收到消息: {}", msg);
    }

    @RabbitListener(queues = "direct.queue1")
    public void directQueue1(String msg) {
        log.info("direct.queue1收到消息: {}", msg);
    }

    @RabbitListener(queues = "direct.queue2")
    public void directQueue2(String msg) {
        log.info("direct.queue2收到消息: {}", msg);
    }

    @RabbitListener(queues = "topic.queue1")
    public void topicQueue1(String msg) {
        log.info("topic.queue1收到消息: {}", msg);
    }

    @RabbitListener(queues = "topic.queue2")
    public void topicQueue2(String msg) {
        log.info("topic.queue2收到消息: {}", msg);
    }


}
